#-------------------------------------------------------------------------------
# Name:        HJ Engine Demo
# Purpose:
#
# Author:      Pablo
#
# Created:     07/03/2012
# Copyright:   (c) Monxcleyr Productions 2012
# Licence:     GPL v3/
#-------------------------------------------------------------------------------
#!/usr/bin/env python


from lib.game import main as game
from lib.game import error
import os, sys, logging, pygame

filename = os.path.join(os.path.split(sys.argv[0])[0], 'hj.log')
if os.path.exists(filename):
  open(filename, 'w').close()
logging.basicConfig(filename= filename, format='%(asctime)s %(levelname)s: %(message)s', datefmt='(%m/%d/%Y %I:%M:%S %p)', level=logging.DEBUG)

def main():

##  sys.argv.append('-release')
  exception = False
  pyscripter = False

  for argv in sys.argv:
    if argv == '-pyscripter':
      pyscripter = True


  if not pyscripter:
    try:
      game.main()
    except Exception, err:
      logging.exception('Exception thrown:')
      exception = True
      pygame.quit()
      errorscreen = error.Error(err)
  else:
    game.main()

  if exception:
    logging.info('Displaying error screen.')
    errorscreen.draw()


if __name__ == '__main__':
  main()